package com.jilijili.service.impl;

import com.jilijili.pojo.Email;
import com.jilijili.service.EmailService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class EmailServiceImpl implements EmailService {

    @Value("${spring.mail.username}")
    public String fromMail;

    @Resource
    public JavaMailSender javaMailSender;


    @Override
    public void sendSimpleMail(Email email) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        // 发件人
        mailMessage.setFrom(fromMail);
        // 收件人
        mailMessage.setTo(email.getTo());
        // 邮件主题
        mailMessage.setSubject(email.getSubject());
        // 邮件内容
        mailMessage.setText(email.getText());
        javaMailSender.send(mailMessage);

    }
}
